﻿using System;

namespace _036_隐藏继承成员
{
    public class A { public int Counter = 1; }
    // 修饰符new把你的意图传达给编译器以及其他编程人员，即重复的成员不是无意的。
    public class B : A { public new int Counter = 2; }

    public class BaseClass
    {
        public virtual void Foo()
        {
            Console.WriteLine("BaseClass.Foo");
        }
    }

    public class Overrider : BaseClass
    {
        public override void Foo()
        {
            Console.WriteLine("Overrider.Foo");
        }
    }

    public class Hider : BaseClass
    {
        public new void Foo()
        {
            Console.WriteLine("Hider.Foo");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Overrider over = new Overrider();
            BaseClass b1 = over;
            over.Foo(); // Overrider.Foo
            b1.Foo(); // Overrider.Foo

            Hider h = new Hider();
            BaseClass b2 = h;
            h.Foo(); // Hider.Foo
            b2.Foo(); // BaseClass.Foo

            Console.ReadKey();
        }
    }
}